import json
from datetime import date
from random import random

from django.http import HttpResponse

from demo_app.models import Person
from demo_app.mongo_fatctory import MongoFactory


# Create your views here.
def hello_world(request):
    return HttpResponse('Hello World')


def get_current_tax_information(request):
    tax_information = {'date': str(date.today()), 'tax': 6 + random()}
    return HttpResponse(json.dumps(tax_information), content_type='application/json')


def do_something_test(request):
    person = Person(first_name='fang', last_name='marvin2', age=20)
    person.save()
    return HttpResponse('test successfully')


def mongo_test(request):
    mongo_factory = MongoFactory()
    result = mongo_factory.customer_collection.find_one()
    print(result)
    return HttpResponse('test')
